/*
 * @Author: lineCode 1145938682@qq.com
 * @Date: 2024-12-08 21:54:19
 * @LastEditors: lineCode
 * @LastEditTime: 2025-06-16 18:35:57
 * @FilePath: /backend/shorthand-modules/shorthand-modules-content/src/main/java/com/angus/modules/content/controller/manage/SysUnitController.java
 */
package com.angus.modules.content.controller.manage;

import com.angus.common.core.web.controller.BaseController;
import com.angus.common.core.web.domain.AjaxResult;
import com.angus.common.log.annotation.Log;
import com.angus.common.log.enums.BusinessType;
import com.angus.common.security.utils.SecurityUtils;
import com.angus.modules.content.domain.SysUnit;
import com.angus.modules.content.dto.SetFeeDto;
import com.angus.modules.content.service.ISysUnitService;
import com.angus.modules.content.vo.SysUnitVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author liyanan
 */
@RestController
@RequestMapping("/unit")
public class SysUnitController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(SysUnitController.class);

    @Resource
    private ISysUnitService sysUnitService;

    // 获取单元线下嗯嗯全部集束
    @GetMapping("/getClusterByUnit")
    public AjaxResult getAllUnitByContentType(@RequestParam @NotBlank(message = "课程编码不能为空") String courseCode, @RequestParam @NotBlank(message = "单元号不能为空") Integer unitNum){
        List<SysUnit> sysUnits = sysUnitService.queryClusterByUnits(courseCode, unitNum);
        return AjaxResult.success(sysUnits);
    }

    // 获取课程下的全部单元
    @GetMapping("/getUnitByCourse")
    public AjaxResult getUnitByCourse(@RequestParam @NotBlank(message = "课程编码不能为空") String courseCode){
        Long userId = SecurityUtils.getUserId();
        List<SysUnitVo> sysUnits = sysUnitService.queryUnits(courseCode,userId);
        return AjaxResult.success(sysUnits);
    }

    // 设置单元信息
    @Log(title = "内容管理", businessType = BusinessType.UPDATE)
    @PutMapping("/setFee")
    public AjaxResult setContentFee(@RequestBody SetFeeDto dto){
        boolean result = sysUnitService.setContentFee(dto);
        return result ?AjaxResult.success("设置成功"):AjaxResult.error("设置失败");
    }

}
